"""
@Author：十
@Time：2024/8/5 12:01
@FileName：upload.py
@Description：数据上传实现
"""
import sys

from PyQt5.QtCore import pyqtSignal
from PyQt5.QtWidgets import QWidget, QApplication

import EdgeIOT
from UI.upload import Ui_Form
from station import SiteWindow


class UploadWindow(QWidget, Ui_Form):
    # 从主窗口获取信息
    Signal_Get_Data = pyqtSignal(object)
    # 获取报文信息
    Signal_Get_Message = pyqtSignal(object)

    def __init__(self, parent=None):
        super(UploadWindow, self).__init__()

        self.parent = parent

        self.data = None

        self.setupUi(self)

        self.SiteWindow = SiteWindow(self)

        self.pushButton.clicked.connect(self.Confirm)

        #
        self.Signal_Get_Data.connect(self.GetData)

    def GetData(self, data):
        # print(data)
        self.data = data
        EdgeIOT.Subscribe_service()
        self.SiteWindow.Signal_Get_Test_Data.emit(self.data)

    # 获取输入框信息和检测设备信息，发送报文
    def Confirm(self):
        try:
            city = self.lineEdit_City.text()
            site = self.lineEdit_Site.text()
            instrument = self.lineEdit_Instrument.text()
            number = self.lineEdit_Number.text()
            # 发送订阅topic
            EdgeIOT.Publish_GetLinkedDevice(city, site)
            self.SiteWindow.show()
            # reply_data, msg = EdgeIOT.Publish_GetLinkedDevice(city, site)
            # print('reply data:', reply_data)
            # if reply_data.get('type') == 'CMD_GET_LINKEDDEVICE' and "service/reply" in msg.topic:
            #     self.SiteWindow.show()
            # self.SiteWindow.Signal_Get_Data.emit(reply_data)
        except Exception as e:
            print("数据上传失败：", e)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    mainWindow = UploadWindow()
    mainWindow.show()
    sys.exit(app.exec_())
